package test;

import instance.InstanceEj1;

import java.util.LinkedList;
import java.util.Random;

import output.Problem1Output;

import problem.ej1.Ej1;

public class testEj1 {
	
//	public static void test1Creciente (String output) throws Exception{
//		
//		int size = 20;
//		int[] arr = new int[size];
//		LinkedList<InstanceEj1> list_insts = new LinkedList<InstanceEj1>();
//		
//		for(int i=0; i<size; i++) arr[i] = i*i;
//		list_insts.add(new InstanceEj1(arr, size));
//		
//		size = 30;
//		arr = new int[size];
//		for(int i=0; i<size; i++) arr[i] = i*i*i;
//		list_insts.add(new InstanceEj1(arr, size));
//		
//		size = 40;
//		arr = new int[size];
//		for(int i=0; i<size; i++) arr[i] = i*i*i*i;
//		list_insts.add(new InstanceEj1(arr, size));
//		
//
//		Problem1Output out = new Problem1Output(output);
//		out.writeInstance(list_insts);
//	}
	
	public static void testCorrectitud(String output) throws Exception{
		
		int size;
		int[] arr;
		LinkedList<InstanceEj1> list_insts = new LinkedList<InstanceEj1>();
	
				/* Escalera Ascendente */
		size = 20;
		arr = new int[size];
		for(int i=0; i<size; i++) arr[i] = i*i;
		list_insts.add(new InstanceEj1(arr, size));
		
		size = 30;
		arr = new int[size];
		for(int i=0; i<size; i++) arr[i] = i*i*i;
		list_insts.add(new InstanceEj1(arr, size));
		
		size = 40;
		arr = new int[size];
		for(int i=0; i<size; i++) arr[i] = i*i*i*i;
		list_insts.add(new InstanceEj1(arr, size));
		
				/* Escalera Descendente */
		size = 17;  
		arr = new int[size];
		for(int i=0, j=20; i<size; i++, j--) arr[i] = j*j;
		list_insts.add(new InstanceEj1(arr, size));
		
		size = 24;
		arr = new int[size];
		for(int i=0, j=27; i<size; i++, j--) arr[i] = j*j*j;
		list_insts.add(new InstanceEj1(arr, size));
		
		size = 31;
		arr = new int[size];
		for(int i=0, j=31; i<size; i++, j--) arr[i] = j*j*j*j;
		list_insts.add(new InstanceEj1(arr, size));
		
				/* Monta�a Ascendente */
		size = 20;
		arr = new int[size];
		for(int i=0, j=5; i<8; i++, j++) arr[i] = j*j;
		for(int i=8, j=2; i<14; i++, j++) arr[i] = j*j*j;
		for(int i=14, j=1; i<20; i++, j++) arr[i] = j*j*j*j;
		list_insts.add(new InstanceEj1(arr, size));
		
		size = 17;
		arr = new int[size];
		for(int i=0, j=5; i<8; i++, j++) arr[i] = j;
		for(int i=8, j=2; i<17; i++, j++) arr[i] = j*j;
		list_insts.add(new InstanceEj1(arr, size));
		
				/* Monta�a Descendente */
		size = 20;
		arr = new int[size];
		for(int i=0, j=20; i<8; i++, j--) arr[i] = j*j;
		for(int i=8, j=21; i<14; i++, j--) arr[i] = j*j*j;
		for(int i=14, j=22; i<20; i++, j--) arr[i] = j*j*j*j;
		list_insts.add(new InstanceEj1(arr, size));
		
				/* Random */
		Random ran = new Random(10);
		size = 10;
		int tmp;
		arr = new int[size];
		for(int i=0; i<size; i++) arr[i] = ((tmp = ran.nextInt())>0) ? tmp%250 : -(tmp%250);
		list_insts.add(new InstanceEj1(arr, size));
		
		ran.setSeed(15);
		size = 10;
		arr = new int[size];
		for(int i=0; i<size; i++) arr[i] = ((tmp = ran.nextInt())>0) ? tmp%250 : -(tmp%250);
		list_insts.add(new InstanceEj1(arr, size));
		
		ran.setSeed(0);
		size = 10;
		arr = new int[size];
		for(int i=0; i<size; i++) arr[i] = ((tmp = ran.nextInt())>0) ? tmp%250 : -(tmp%250);
		list_insts.add(new InstanceEj1(arr, size));
		
		ran.setSeed(5);
		size = 10;
		arr = new int[size];
		for(int i=0; i<size; i++) arr[i] = ((tmp = ran.nextInt())>0) ? tmp%250 : -(tmp%250);
		list_insts.add(new InstanceEj1(arr, size));
		
		Problem1Output out = new Problem1Output(output);
		out.writeInstance(list_insts);
	}
	
	public static void generarEscalera(int n, boolean ascendente, String archsalida) throws Exception{
		/* IMPORTANTE: n>=20 */
		LinkedList<InstanceEj1> res = new LinkedList<InstanceEj1>();
		Random rnd = new Random();
		for (int i = 20; i < n; i++) {
			int[] secuencia = new int[i];
			if(ascendente) secuencia[0]= rnd.nextInt(10000);
			else secuencia[0]= 1000000;
			for(int j = 1; j<i; j++){
				int num = rnd.nextInt(10000);
				if(!ascendente) num = num *-1;
				secuencia[j]= secuencia[j-1] + num;
			}
			InstanceEj1 inst = new InstanceEj1(secuencia, secuencia.length);
			res.add(inst);
		}
		Problem1Output salida = new Problem1Output(archsalida);
		salida.writeInstance(res);
	}
	
	public static void generartodosIguales(int n, String archsalida) throws Exception{
		/* IMPORTANTE: n>=20 */
		LinkedList<InstanceEj1> res = new LinkedList<InstanceEj1>();
		Random rnd = new Random();
		for (int i = 20; i < n; i++) {
			int[] secuencia = new int[i];
			int num = rnd.nextInt(100000);
			for(int j = 1; j<i; j++){
				secuencia[j]= num;
			}
			InstanceEj1 inst = new InstanceEj1(secuencia, secuencia.length);
			res.add(inst);
		}
		Problem1Output salida = new Problem1Output(archsalida);
		salida.writeInstance(res);
	}
	
	public static void generarRandom(int n, String archsalida) throws Exception{
		/* IMPORTANTE: n>=20 */
		LinkedList<InstanceEj1> res = new LinkedList<InstanceEj1>();
		Random rnd = new Random();
		for (int i = 20; i < n; i++) {
			int[] secuencia = new int[i];
			for(int j = 1; j<i; j++){
				secuencia[j]= rnd.nextInt(100000);
			}
			InstanceEj1 inst = new InstanceEj1(secuencia, secuencia.length);
			res.add(inst);
		}
		Problem1Output salida = new Problem1Output(archsalida);
		salida.writeInstance(res);
	}

	public static void main(String[] args) throws Exception{
//		test1Creciente("./src/resources/Ej1/creciente.in");
//		Ej1.AlgoritmoPpal("./src/resources/Ej1/creciente.in", false);
		
		testCorrectitud("./src/resources/Ej1/correctitud.in");
		Ej1.AlgoritmoPpal("./src/resources/Ej1/correctitud.in", false);
		
		generarEscalera(100, true, "./src/resources/Ej1/ascendente.in");
		Ej1.AlgoritmoPpal("./src/resources/Ej1/ascendente.in", true);
		
		generarEscalera(100, false, "./src/resources/Ej1/descendente.in");
		Ej1.AlgoritmoPpal("./src/resources/Ej1/descendente.in", true);
		
		generarRandom(100, "./src/resources/Ej1/random.in");
		Ej1.AlgoritmoPpal("./src/resources/Ej1/random.in", true);
		
		generartodosIguales(100, "./src/resources/Ej1/todosiguales.in");
		Ej1.AlgoritmoPpal("./src/resources/Ej1/todosiguales.in", true);
		
	}
}